package com.coocaa.app.support.thread;

import java.util.concurrent.ThreadFactory;

public class CCThread {
    public static final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
        }
    };

    public static final ThreadFactory newThreadFactory(String name) {
        return new ThreadFactory() {
            private int count = 0;

            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r, "name-" + count++);
                thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
                return thread;
            }
        };
    }
}
